/**
 * Copyright ©2016-2020 tianyu education Corporation, All Rights Reserved
 * http://www.whty.com.cn/
 */
package profile.hujia.profile.elasticsearch.study.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import profile.hujia.profile.elasticsearch.study.model.SourceEntity;
import profile.hujia.profile.elasticsearch.study.service.SourceService;

import java.util.List;

/**
 * class info
 *
 * @author hujia
 * @date 2019-09-10 09:18
 */
@RestController
@RequestMapping
@Slf4j
public class SourceController {

    @Autowired
    SourceService sourceService;

    @PostMapping("/addSource")
    public void addSourceEntity(@RequestBody SourceEntity sourceEntity) {
        try {
            sourceService.addSource(sourceEntity);
        }catch (Exception ex){
            log.error("error"+ex);
            return;
        }
    }

    @PostMapping("/addSourceList")
    public void addSourceList(@RequestBody List<SourceEntity> sourceEntityList){
        try {
            sourceService.addSourceList(sourceEntityList);
        }catch (Exception ex){
            log.error("error"+ex);
            return;
        }
    }

    @GetMapping("/listAll")
    public List<SourceEntity> listAllResource(){
        try {
           return  sourceService.listAll();
        }catch (Exception ex){
            log.error("error"+ex);
            return null;
        }
    }

    @PostMapping("/saveToTxt")
    public void saveToTest(@RequestBody String path){
        try {
            sourceService.saveToTxt(path);
        } catch (Exception ex) {
            log.error("error"+ex);
            return ;
        }
    }

    @PostMapping("/getDocument")
    public void getDocument(@RequestBody String id){
        try {
            sourceService.getDocument(id);
        } catch (Exception ex) {
            log.error("error"+ex);
            return ;
        }
    }

    @PostMapping("/deleteDocumentObject")
    public void deleteDocument(@RequestBody SourceEntity sourceEntity){
        try {
            sourceService.deleteDocument(sourceEntity);
        } catch (Exception ex) {
            log.error("error"+ex);
            return ;
        }
    }

    @PostMapping("/deleteDocumentId")
    public void deleteDocument(@RequestBody String id){
        try {
            sourceService.deleteDocument(id);
        } catch (Exception ex) {
            log.error("error"+ex);
            return ;
        }
    }

    @PostMapping("/updateDocument")
    public void updateDocument(@RequestBody SourceEntity sourceEntity){
        try {
            sourceService.updateDocument(sourceEntity);
        } catch (Exception ex) {
            log.error("error"+ex);
            return ;
        }
    }

    @PostMapping("/updateDocumentList")
    public void updateDocumentList(@RequestBody List<SourceEntity> sourceEntityList){
        try {
            sourceService.updateDocumentList(sourceEntityList);
        } catch (Exception ex) {
            log.error("error"+ex);
            return ;
        }
    }
}
